package Offer;

import java.util.Stack;

/**
 * @author 韩迪
 * @date 2022/04/01 20:13
 **/
public class Code09 {//用两个栈实现队列

    class CQueue {
        Stack<Integer> s1 = new Stack<>();
        Stack<Integer> s2 = new Stack<>();;
        int size = 0;

        public CQueue() {
        }

        public void appendTail(int value) {
            s1.push(value);
            size++;
        }

        public int deleteHead() {
            if (s1.isEmpty())
                return -1;
            //先将s1内容出栈入s2
            while (!s1.isEmpty()){
                Integer i = s1.pop();
                s2.push(i);
            }
            int ret = s2.pop();//队首元素出栈
            size--;
            //再将s2内容出栈入至s1
            while (!s2.isEmpty()){
                s1.push(s2.pop());
            }
            return ret;

        }
    }

    public static void main(String[] args) {
        CQueue queue = new Code09().new CQueue();
        queue.appendTail(1);
        queue.appendTail(2);
        System.out.println(queue.deleteHead());
    }
}
